﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.huigo.Framework.ServiceUtils;
using com.loto.Common;

namespace com.huigo.B2B.Web.center.account
{
    public partial class UpdatePwd : BasePage
    {
        private string beforePwd
        {
            get
            {
                return string.IsNullOrEmpty(Request.Form["beforePwd"]) ? string.Empty : com.loto.Common.Utils.SqlEscape(Request.Form["beforePwd"]);
            }
        }
        private string newPwd
        {
            get
            {
                return string.IsNullOrEmpty(Request.Form["newPwd"]) ? string.Empty : com.loto.Common.Utils.SqlEscape(Request.Form["newPwd"]);
            }
        }
        private string newPwdAgain
        {
            get
            {
                return string.IsNullOrEmpty(Request.Form["newPwdAgain"]) ? string.Empty : com.loto.Common.Utils.SqlEscape(Request.Form["newPwdAgain"]);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form["isPost"] == "true")
            {
                if (string.IsNullOrEmpty(beforePwd))
                {
                    MessageBox.Show(this.Page, "请输入当前登录密码！");
                    return;
                }
                else if (string.IsNullOrEmpty(newPwd))
                {
                    MessageBox.Show(this.Page, "请输入新密码！");
                    return;
                }
                else if (string.IsNullOrEmpty(newPwdAgain))
                {
                    MessageBox.Show(this.Page, "请再次输入密码！");
                    return;
                }
                else if (newPwd != newPwdAgain)
                {
                    MessageBox.Show(this.Page, "两次输入的密码不一样！");
                    return;
                }
                else
                {
                    List<RequestFuncParams> list = new List<RequestFuncParams>();
                    list.Add(new RequestFuncParams("custFid", CustId.ToString()));
                    list.Add(new RequestFuncParams("password", beforePwd.ToString()));
                    BaseService service = new BaseService();
                    ParserXml parser = service.RequestEntryService(Dict.ERequestFunc.GET_CUST_PWD, list);
                    if (parser != null && parser.RowsCount > 0)
                    {
                        if (parser["returnargs", 0] == "true")
                        {
                            List<RequestFuncParams> arryList = new List<RequestFuncParams>();
                            arryList.Add(new RequestFuncParams("custFid", CustId.ToString()));
                            arryList.Add(new RequestFuncParams("pwd", newPwd.ToString()));
                            BaseService baseService = new BaseService();
                            ParserXml parserPwd = baseService.RequestEntryService(Dict.ERequestFunc.UPDATE_PWD, arryList);
                            if (parserPwd != null && parserPwd.RowsCount > 0)
                            {
                                if (parserPwd["returnargs", 0] == "1")
                                {
                                    MessageBox.Show(this.Page, "修改成功！");
                                }
                                else
                                {
                                    MessageBox.Show(this.Page, "修改失败！");
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show(this.Page, "当前登录密码不正确！");
                            return;
                        }
                    }                    
                }
            }
        }
    }
}
